<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加老师的任职</title>
    <link href="../../static/css/bootstrap.min.css" rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}">
    <!-- Custom styles for this template -->
    <link href="../../static/css/dashboard.css" rel="stylesheet" th:href="@{/static/css/dashboard.css}">
    <script src="../../static/js/jquery-3.6.0.min.js" th:src="@{/static/js/jquery-3.6.0.min.js}"
            type="text/javascript"></script>
</head>
<body>
<div th:insert="admin/common::topbar"></div>
<div class="container-fluid">
    <div class="row">
        <!--侧边栏-->
        <div th:insert="~{admin/common::sidebar(active='teacherList.html')}">
        </div>
        <!--"-->
        <main class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4" role="main">
            <form class="container-fluid col-md-5 col-md-pull-3" method="post" th:action="@{/admin/addClassTeacher}">
                <p style="color: red" th:if="${not #strings.isEmpty(msg)}" th:text="${msg}"></p>
                <div class="form-group">
                    <label for="tid">任职教师</label>
                    <select class="form-control" id="tid" name="tid">
                        <option th:each="teacher:${teacherList}" th:text="${teacher.getTname()}"
                                th:value="${teacher.getTid()}"></option>
                    </select>
                </div>
                <div class="form-group">
                    <!--
                    逻辑漏洞
                    教学科目将绑定教师科目
                    selected:
                    -->
                    <label for="subject">教学科目</label>
                    <select class="form-control" id="subject" name="subject">
                        <option th:each="course:${courseList}" th:text="${course.cname}"
                                th:value="${course.cid}"></option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="className">教学班级</label>
                    <select class="form-control" id="className" name="className">
                        <option th:each="classObject:${classInfo}" th:text="${classObject.class_name}"
                                th:value="${classObject.classid}"></option>
                    </select>
                </div>
                <button class="btn btn-primary " id="button" type="submit">添加</button>
            </form>
        </main>
    </div>
</div>

<script src="../../static/js/popper.min.js" th:src="@{/static/js/popper.min.js}" type="text/javascript"></script>
<script src="../../static/js/bootstrap.min.js" th:src="@{/static/js/bootstrap.min.js}" type="text/javascript"></script>
<!-- Icons -->
<script src="../../static/js/feather.min.js" th:src="@{/static/js/feather.min.js}" type="text/javascript"></script>
<!-- Graphs -->
<script src="../../static/js/Chart.min.js" th:src="@{/static/js/Chart.min.js}" type="text/javascript"></script>
<script>
    let tid = $('#tid');
    //let subject = $('#subject');
    //let className=$('#className');
    $(function () {
        tid.change(function () {
            $.get({
                url: "/admin/ajax/getTeacher",
                data: {"tid": tid.val()},
                success: function (result) {
                    if (result !== null) {
                        // alert(result.tid);
                        $('#subject option').each(function () {
                            if ($(this).text() === result.subject) {
                                $(this).attr("selected", true);
                            }
                        })
                        $('#className option').each(function () {
                            if ($(this).text() === result.class_name) {
                                $(this).attr("selected", true);
                            }
                        })

                        /*  $("#subject option[value=result").attr("selected",'selected');
                          $('#className option[value="map.classid"]').attr("selected",'selected');*/
                    }
                }
            })
        })
    })

</script>
</body>
</html>